{% extends 'base.html' %}
{% load static %}

{% block title %}网上商城-购物车{% endblock title %}

{% block content %}

	{% include 'header-con.html' %}

	{% include 'search-bar.html' %}

	<div class="total_count">全部商品<em>{{ total_count }}</em>件</div>	
	<ul class="cart_list_th clearfix">
		<li class="col01">商品名称</li>
		<li class="col02">商品单位</li>
		<li class="col03">商品价格</li>
		<li class="col04">数量</li>
		<li class="col05">小计</li>
		<li class="col06">操作</li>
	</ul>
	<form action="/order/place/" method="post" id="order_form">
		{% for good in goods %}
		<ul class="cart_list_td clearfix">
			<li class="col01"><input type="checkbox" name="sku_id" value="{{ good.id }}" checked></li>
			<li class="col02"><img src="{{ good.image.url }}"></li>
			<li class="col03">{{ good.name }}<br><em>{{ good.price }}元/{{ good.unite }}</em></li>
			<li class="col04">{{ good.unite }}</li>
			<li class="col05">{{ good.price }}元</li>
			<li class="col06">
				<div class="num_add">
					<a href="javascript:;" class="add fl">+</a>
					<input name="count" type="text" good_id="{{ good.id }}" class="num_show fl" value="{{ good.count }}">	
					<a href="javascript:;" class="minus fl">-</a>	
				</div>
			</li>
			<li class="col07">{{ good.amount }}元</li>
			<li class="col08"><a href="javascript:">删除</a></li>
		</ul>
		{% endfor %}
		{% csrf_token %}
	</form>


	<ul class="settlements">
		<li class="col01"><input type="checkbox" name="" checked=""></li>
		<li class="col02">全选</li>
		<li class="col03">合计(不含运费)：<span>¥</span><em>{{ total_price }}</em><br>共计<b>{{ total_count }}</b>件商品</li>
		<li class="col04"><a href="javascript:" onclick="$('#order_form').submit()">去结算</a></li>
	</ul>

	{% csrf_token %}

	<script type="text/javascript" src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
	<script type="text/javascript" src="{% static 'js/cart.js' %}"></script>
    <script>
        $(document).ready(function () {
        // 表单提交时检查是否有商品，如果没有则阻止提交并弹出警告框
        $('#order_form').on('submit', function (event) {
            // 获取表单中的商品数量
            var goodsCount = $('.cart_list_td').length;
            
            // 如果没有商品，阻止表单提交并弹出警告框
            if (goodsCount === 0) {
                event.preventDefault(); // 阻止表单提交
                alert('购物车中没有商品，请添加商品后再提交订单。');
            }
        });
    });

    </script>
{% endblock content %}

